﻿<?php 
	include("../../config/database.php");
	include("../../includes/functions/common_functions.php");
	tep_db_connect() or die('Unable to connect to database server!');
?>

<script >
	
	function edit(obj)
	{
		$(obj).parent('tr').find('#in').show();
		$("#product_name p").hide();
		//$("#product_name input").show();
	}
	function deletePro(obj,product_id){
		if(confirm("Do you want to delete this item?")){
			$(obj).parents('tr').remove();
			$.post("san_pham_config.php",{method:"delete",proId:product_id},function(){
			});
		}		
	}
	function deleteAll(obj){
		var proIds=[];
		var m=0;
		var tr=$('#rounded-corner').find("tr");		
		if($(tr).length>3){//table co 3 dong tro len tinh header va footer
			for(i=1,j=0;i<$(tr).length;i++){
				var td=$(tr[i]).find("td");
				var chk=$(td[0]).find('input[name=chk_pro]');
				if($(chk).is(':checked')){					
					$('input[name=hid_proId[]]').val($(chk).val());
					proIds[j++]=$(chk).val();
					m++;
				}
			}
			if(m>0){
				if(confirm("Do you want to delete items?")){
					$.post("san_pham_config.php",{method:"deleteAll",'proIds[]':proIds},function(){
					});				
					for(i=1,j=0;i<$(tr).length;i++){
						var td=$(tr[i]).find("td");
						var chk=$(td[0]).find('input[name=chk_pro]');
						if($(chk).is(':checked')){				
							$(tr[i]).remove();					
						}
					}
				}
				
			}
		}
	}
</script>
<h2>Thông tin sản phẩm</h2> 
<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
    <thead>
    	<tr>
        	<th scope="col" class="rounded-company"></th>
            <th scope="col" class="rounded">Tên sản phẩm</th>            
            <th scope="col" class="rounded">Giá</th>
            <th scope="col" class="rounded">Ngày cập nhật</th>
			<th scope="col" class="rounded">Hình ảnh</th>
			<th scope="col" class="rounded">Danh mục</th>			
            <th scope="col" class="rounded">Sửa</th>
            <th scope="col" class="rounded-q4">Xóa</th>
        </tr>
    </thead>
        <tfoot>
    	<tr>
        	<td colspan="7" class="rounded-foot-left"><em>Hiển thị thông tin sản phẩm.</em></td>        	
			<td class="rounded-foot-right" colspan="2">&nbsp;</td>
        </tr>
    </tfoot>
	<?php
		// Hien thi thông tin sản phẩm
		$sql="SELECT * from products_description cd 
									inner join (select *from products_to_categories) ptc on cd.products_id=ptc.products_id 
									inner join (SELECT * FROM products) p ON p.products_id=ptc.products_id";
		// Ten san pham,mo ta ,gia ,ngay cap nhat,danh muc, hinh anh
		$per_page=12;		
		$page = $_REQUEST['page']?$_REQUEST['page']:1;		
		$url="index.php?action=product";
		$num_show=5;	
		$total=mysql_num_rows(mysql_query($sql));
		$paging=paging($total,$per_page,$page,$url,$num_show);		
		$sql.=" LIMIT {$paging['offset']}, $per_page";
		$result=mysql_query($sql);		
		
	?>
    <tbody>
	<input type="hidden" name="hid_proId[]" value="" />
	<?php 
		while($row=mysql_fetch_assoc($result))
		{
		?>
    	<tr>
        	<td width="10px"><input type="checkbox" name="chk_pro" value="<?php echo $row['products_id']?>"  /></td>
            <td width="10px"><div id="product_name"><input id="in" type="text" value="<?php echo $row['products_name'];?>" style="display:none;" />
			<p><?php echo $row['products_name'];?></p></div></td>
            <td width="10px" ><?php echo $row['products_price'];?></td>
            <td width="10px"><?php echo $row['products_date_available'];?></td>
            <td><p style="width:20px;"><?php echo $row['products_image'];?></p></td>
			<td width="10px"><?php echo $row['categories_id'];?></td>			
		<td width="10px"><a href="?action=edit&proId=<?php echo $row['products_id'];?>"/><img src="../images/user_edit.png" onclick="edit(this)"  alt="" title="" border="0" /></a></td>
		<td width="10px"><img src="../images/trash.png" onclick="deletePro(this,<?php echo $row['products_id'];?>)" alt="" title="" border="0" /></td>
        </tr>
        <?php 
		}
		?>
    	
    </tbody>
</table>
 <div class="right_content">     
	<!-- <a href="#" class="bt_green" ><span class="bt_green_lft"></span><strong>Add new item</strong><span class="bt_green_r"></span></a>
     <a href="#" class="bt_blue"><span class="bt_blue_lft"></span><strong>View all items from category</strong><span class="bt_blue_r"></span></a>-->
     <a href="#" class="bt_red" onclick="deleteAll(this)"><span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span></a> 
     
     
        <div class="pagination">
		<?php 
			echo $paging['paging'];
		?>
        <!--<span class="disabled"><< prev</span><span class="current">1</span><a href="">2</a><a href="">3</a>
		<a href="">4</a><a href="">5</a><a href="">10</a><a href="">11</a><a href="">12</a>...<a href="">100</a><a href="">101</a><a href="">next >></a>-->
        </div> 
 </div><!-- end of right content-->
